#include "regri_env.h"

regri_env_t             regri_record = {.env_lock=1};
void   get_regri_env(regri_env_t * dest)
{
			portENTER_CRITICAL();								
			memcpy(dest,&regri_record,sizeof(regri_env_t));
			portEXIT_CRITICAL();
}
void   set_regri_env( regri_env_t * src)
{
			portENTER_CRITICAL();								
			memcpy(&regri_record,src,sizeof(regri_env_t));
			portEXIT_CRITICAL();
}
#define		_DEFINE_ENVFUN(_type,_name,_vty)					\
				void regri_env_set_##_name(_vty value)\
				{																												\
							portENTER_CRITICAL();								\
							regri_record.##_type.##_name = value;\
							portEXIT_CRITICAL();\
				} \
				void regri_env_get_##_name(_vty *value)\
				{																												\
							portENTER_CRITICAL();								\
							*value = regri_record.##_type.##_name;\
							portEXIT_CRITICAL();\
				} 
 
void printf_env()
{
	printf("short_circuit_breakdown = %d,\r\n ,\
	water_full_breakdown = %d,\r\n \
	high_temperature_breakdown = %d,\r\n \
	low_temperature_breakdown = %d,\r\n \
	beyondMaxTemp_warning = %d,\r\n \
	beyondMinTemp_warning = %d,\r\n \
	regrigeration_state = %d,\r\n \
	heating_state = %d,\r\n \
	force_regri_state = %d,\r\n \
	unlock = %d,\r\n \
	cabinet_temperature = %d,\r\n",regri_record.breakdown.short_circuit_breakdown,\
	regri_record.breakdown.water_full_breakdown,\
	regri_record.breakdown.high_temperature_breakdown,\
	regri_record.breakdown.low_temperature_breakdown,\
	regri_record.warring.beyondMaxTemp_warning,\
	regri_record.warring.beyondMinTemp_warning,\
	regri_record.relay_state.regrigeration_state,\
	regri_record.relay_state.heating_state,\
	regri_record.relay_state.force_regri_state,\
	regri_record.env_lock.unlock,\
	regri_record.temperature.cabinet_temperature
	);

}	
_DEFINE_ENVFUN(breakdown,short_circuit_breakdown,uint16_t)
_DEFINE_ENVFUN(breakdown,water_full_breakdown,uint16_t)
_DEFINE_ENVFUN(breakdown,high_temperature_breakdown,uint16_t)
_DEFINE_ENVFUN(breakdown,low_temperature_breakdown,uint16_t)

_DEFINE_ENVFUN(warring,beyondMaxTemp_warning,uint16_t)
_DEFINE_ENVFUN(warring,beyondMinTemp_warning,uint16_t)

_DEFINE_ENVFUN(relay_state,regrigeration_state,uint16_t)
_DEFINE_ENVFUN(relay_state,heating_state,uint16_t)
_DEFINE_ENVFUN(relay_state,force_regri_state,uint16_t)

_DEFINE_ENVFUN(env_lock,unlock,uint16_t)

_DEFINE_ENVFUN(temperature,cabinet_temperature,uint16_t)
